//
//  CoverViewController.m
//  WuLi
//
//  Created by Gollum on 16/9/3.
//  Copyright © 2016年 Gollum. All rights reserved.
//

#import "CoverViewController.h"
#import "NetworkTool.h"
@interface CoverViewController ()
@property (weak, nonatomic) IBOutlet UIView *threeButtonView;

@property (weak, nonatomic) IBOutlet UIImageView *mainImage;
@property (nonatomic,strong)UIImageView *imageView;

//监控是否点击
@property (nonatomic,assign)BOOL isTap;
@end

@implementation CoverViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    [self handleData];

    UITapGestureRecognizer *tapView = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapMainView:)];
    [self.view addGestureRecognizer:tapView];
    
    }
- (void)viewDidAppear:(BOOL)animated{

    [UIView animateWithDuration:0.5 delay:2 options:UIViewAnimationOptionLayoutSubviews animations:^{
        _threeButtonView.alpha = 0;
    } completion:^(BOOL finished) {
        
    }];


}
- (void)handleData{

    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    NSString *imageUrl = [userDefaults objectForKey:@"adImageUrl"];
    NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:imageUrl]];
    _mainImage.image = [UIImage imageWithData:data];

}
- (IBAction)handleBack:(id)sender {
    [self dismissViewControllerAnimated:YES completion:^{
        
    }];
}
- (IBAction)downLoad:(id)sender {
    
    
    
    
    
    
    
    
}
- (IBAction)shareButton:(id)sender {
    
    _imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
    [self.view addSubview:_imageView];
    _imageView.userInteractionEnabled = YES;
    
    UIBlurEffect *blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
    UIVisualEffectView *effectView = [[UIVisualEffectView alloc] initWithEffect:blurEffect];
    effectView.frame = CGRectMake(0, 0, _imageView.frame.size.width, _imageView.frame.size.height);
    [_imageView addSubview:effectView];
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapImageView:)];
    [_imageView addGestureRecognizer:tap];
}

- (void)tapImageView:(UITapGestureRecognizer *)tap {


    [_imageView removeFromSuperview];

}
- (void)tapMainView:(UITapGestureRecognizer *)tapMainView{

    if (_isTap == NO) {
        [UIView animateWithDuration:0.5 animations:^{
//            [_threeButtonView removeFromSuperview];
            _threeButtonView.alpha = 0;
        } completion:^(BOOL finished) {
            
        }];
    }else{
    
        [UIView animateWithDuration:0.5 animations:^{
//            [_imageView addSubview:_threeButtonView];
            _threeButtonView.alpha = 1;
        } completion:^(BOOL finished) {
            
        }];
    
    }
    _isTap = !_isTap;
    
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
